﻿using PLCS.Domain.Shared.Processes;
using TaskStatus = PLCS.Domain.Shared.Tasks.TaskStatus;

namespace PLCS.Domain.Orders;

/// <summary>
/// 工单运行情况表
/// </summary>
public class OrderRunningCondition : BaseEntity
{
    /// <summary>
    /// 第几步骤
    /// </summary>
    public int WhichStep { get; set; }

    /// <summary>
    /// 最终工序
    /// </summary>
    public string ProcessNo { get; set; }

    /// <summary>
    /// 工序放行信号（来自MES或PLC）
    /// </summary>
    public bool IsPermit { get; set; }

    /// <summary>
    /// 是否下线
    /// </summary>
    public YesNo IsEnd { get; set; }

    /// <summary>

    /// 工序状态
    /// </summary>
    public ProcessStatus ProcessStatus { get; private set; }

    /// <summary>
    /// 工单号（相当于逻辑外键）
    /// </summary>
    public string OrderNo { get; set; }

    [NotMapped]
    public Order? Order { get; set; }

    [NotMapped]
    public HisOrder? HisOrder { get; set; }

    public OrderRunningCondition()
    {
    }

    public OrderRunningCondition(string processNo, int whichStep, Order order, YesNo isEnd)
    {
        ProcessStatus = ProcessStatus.未执行;
        WhichStep = whichStep;
        Order = order;
        OrderNo = order.OrderNo;
        ProcessNo = processNo;
        IsEnd = isEnd;
        CreationTime = DateTime.Now;
    }

    public OrderRunningCondition ChangeStatus(ProcessStatus status)
    {
        ProcessStatus = status;
        return this;
    }
}